//
//  FontUtil.m
//  Extend
//
//  Created by 陆海升 on 2018/1/16.
//  Copyright © 2018年 敬信. All rights reserved.
//

#import "FontUtil.h"
#define CustomFontName @"PingFangSC-Light"
@implementation UILabel (FontUtil)

+ (void)load{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode{
    [self myInitWithCoder:aDecode];
    if (self) {
        //部分不像改变字体的 把tag值设置成333跳过
        if(self.tag != 333) {
            CGFloat fontSize = self.font.pointSize;
            self.font = [UIFont fontWithName:CustomFontName size:fontSize];
        }
    }
    return self;
}
@end

@implementation UIButton (fontUtil)

+ (void)load{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode{
    [self myInitWithCoder:aDecode];
    if (self) {
        
        //部分不像改变字体的 把tag值设置成333跳过
        if(self.tag != 333){
            CGFloat fontSize = self.titleLabel.font.pointSize;
            self.titleLabel.font = [UIFont fontWithName:CustomFontName size:fontSize];
        }
    }
    return self;
}

@end


@implementation UITextField (fontUtil)

+ (void)load{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode{
    [self myInitWithCoder:aDecode];
    if (self) {
        //部分不像改变字体的 把tag值设置成333跳过
        if(self.tag != 333){
            CGFloat fontSize = self.font.pointSize;
            self.font = [UIFont fontWithName:CustomFontName size:fontSize];
        }
    }
    return self;
}

@end


@implementation UITextView (fontUtil)

+ (void)load{
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder*)aDecode{
    [self myInitWithCoder:aDecode];
    if (self) {
        //部分不像改变字体的 把tag值设置成333跳过
        if(self.tag != 333 ){
            CGFloat fontSize = self.font.pointSize;
            self.font = [UIFont fontWithName:CustomFontName size:fontSize];
        }
    }
    return self;
}

@end

